package com.liuxin.mycontactdemo.dbhelper;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.provider.BaseColumns;

import androidx.annotation.Nullable;

public class ContactOpenHelper extends SQLiteOpenHelper {
    public static  final  String T_CONTACT="t_contact";
    //定义联系人表结构
    public  class ContactTable implements BaseColumns {//使用该接口可以默认增加一列_id
        /*表中有五个字段
         1._id
         2.name
         3.phone
         4.email
         5.qq
        */
        public  static  final  String NAME="name";
        public  static  final  String PHONE="phone";
        public  static  final  String EMAIL="email";
        public  static  final  String QQ="qq";
    }
    public ContactOpenHelper(Context context) {
        super(context, "context.db", null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String sql="Create table "+T_CONTACT+" ("
                +ContactTable._ID+" integer PRIMARY KEY AUTOINCREMENT,"
                +ContactTable.NAME+" text,"
                +ContactTable.PHONE+" text,"
                +ContactTable.EMAIL+" text,"
                +ContactTable.QQ+" text)";
        db.execSQL(sql);
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {

    }
}
